<?php
require_once '../sub/init.php';
if(!in_array('chat',$navarr))exit('该功能已关闭');
if($submitok== 'ajax_get_audio_url'){
	if(empty($audio_url)){
		json_exit(array('flag'=>0,'msg'=>'获取文件参数失败'));
	}else{
		$audio_url=str_replace($_ZEAI['up2'],"",$audio_url);
		
		if(substr($audio_url,0,1)=="/"){
			$audio_url=substr($audio_url,1);
		}
		if(file_exists(ZEAI.'up/'.$audio_url)){
			json_exit(array('flag'=>1,'msg'=>'存在可用','url'=>UP.$audio_url));
		}else{
			$audio_url=str_replace("v/","tmp/",$audio_url);
			$audio_url=str_replace(".mp3",".amr",$audio_url);
			if(file_exists(ZEAI.'up/'.$audio_url)){
				json_exit(array('flag'=>1,'msg'=>'存在可用','url'=>UP.$audio_url));
			}else{
				json_exit(array('flag'=>0,'msg'=>'文件不存在'.$audio_url));
			}
		}			
	}
	exit;	
}
if(!is_mobile())header("Location: ".a('{"kind":"u","mp":"p","uid":'.$uid.'}'));

$uid = (ifint($uid))?$uid:$a;$ii=$i;
if (!ifint($uid))zeaialert('{"title":"此用户不存在或已被注销","btnt":"朕知道了","url":"-1"}');
if ($uid == $cook_uid)zeaialert('{"title":"亲，和自己发消息有意义么？","btnt":"朕知道了","url":"-1"}');
if(!in_array('chat',$navarr))zeaialert('{"title":"亲，聊天功能已关闭","btnt":"朕知道了","url":"-1"}');

$currfields = "sex,grade,photo_s,photo_f,nickname,RZ,myinfobfb,tipnum,sign_pdf_flag";
/*$$rtn='json';*/$jumpurl=a('{"kind":"u","mp":"m","uid":'.$uid.'}');
require_once ZEAI.'m/my_chk_u.php';
require_once ZEAI.'cache/udata.php';

//检查拉黑
if (gzflag($uid,$cook_uid) == -1)zeaialert('{"title":"你已将对方拉黑了,还聊天？","btnt":"朕知道了","url":"-1"}');
if (gzflag($cook_uid,$uid) == -1)zeaialert('{"title":"对方觉得你不太适合Ta，请求失败","btnt":"朕知道了","url":"-1"}');
require_once ZEAI.'cache/config_up.php';
require_once ZEAI.'cache/config_vip.php';
//我的
$cook_sex       = intval($row['sex']);
$cook_grade    = $row['grade'];
$cook_photo_s  = $row['photo_s'];
$cook_photo_f   = intval($row['photo_f']);
$cook_nickname = dataIO($row['nickname'],'out');
$cook_RZ = $row['RZ'];$cook_RZarr = explode(',',$cook_RZ);
$cook_myinfobfb = intval($row['myinfobfb']);
$data_tipnum    = intval($row['tipnum']);
$cook_sign_pdf_flag  = $row['sign_pdf_flag'];
//对方
$row = $db->ROW(__TBL_USER__,"sex,photo_s,photo_f,nickname,openid,grade,photo_ifshow,birthday,heigh,pay,edu","flag=1 AND id=".$uid);
if ($row){
	$sex      = $row[0];
	$photo_s  = $row[1];
	$photo_f  = $row[2];
	$nickname = trimhtml(dataIO($row[3],'out'));
	$openid   = $row[4];
	$grade    = $row[5];$Ugrade=$grade;
	$photo_ifshow = $row[6];
	$birthday = $row[7];
	$heigh    = $row[8];
	$pay      = $row[9];
	$edu      = $row[10];
}else{zeaialert('{"title":"此用户不存在或已被注销","btnt":"朕知道了","url":"-1"}');}

//聊天/查看联系方式
$chatContact_data = explode(',',$_VIP['chatContact_data']);
if(count($chatContact_data)>0 && is_array($chatContact_data)){
	//前置条件
	if(empty($cook_photo_s))$cook_photo_f=0;
	$json=array("ARR"=>$chatContact_data,"jumpurl"=>$jumpurl,"RZarr"=>$cook_RZarr,"sex"=>$sex,"cook_sex"=>$cook_sex,"cook_grade"=>$cook_grade,"cook_photo_f"=>$cook_photo_f,"cook_myinfobfb"=>$cook_myinfobfb,"data_bfb_num"=>intval($_VIP['chatContact_bfb_num']),"cook_sign_pdf_flag"=>$cook_sign_pdf_flag,"js"=>$js);
	Before_TJ(encode_json($json));
}
//
$chat_duifangfree = json_decode($_VIP['chat_duifangfree'],true);
$chat_send_iffree = json_decode($_VIP['chat_send_iffree'],true);
$chat_hf_iffree = json_decode($_VIP['chat_hf_iffree'],true);
$chat_duifangfree_send = json_decode($_VIP['chat_duifangfree_send'],true);
$urole = json_decode($_ZEAI['urole']);
$ifchatlock = lockU($uid);//是否已解锁
$photo_s_str = photo_s_out('{"smb":"s","sex":"'.$sex.'","photo_s":"'.$photo_s.'","photo_f":"'.$photo_f.'","photo_ifshow":"'.$photo_ifshow.'","uflag":"'.$uflag.'","outkind":"img"}');
$cook_photo_s_str = (!empty($cook_photo_s) && $cook_photo_f==1)?'<img src="'.UP.$cook_photo_s.'">':'<img src="'.RES."photo_m".$cook_sex.'.png">';
switch ($submitok) {
	case 'ajax_lockopen':
		nolevel($uid,$cook_uid,'chat',$jumpurl);
		noucount_clickloveb($uid,$cook_uid,'chat');
		json_exit(array('flag'=>1,'msg'=>'解锁成功'));
	break;
	case 'ajax_add':
		//发信总开关
		if(!$ifchatlock && $chat_send_iffree[$cook_grade]!=1){
			$chat_send_iffree_str='';
			foreach (@$urole as $uv){
				$grade = $uv->g;
				$title = $uv->t;
				if($chat_send_iffree[$grade]==1)$chat_send_iffree_str.='【'.$title.'】<br>';
			}
			if(empty($chat_send_iffree_str))$chat_send_iffree_str='VIP';
			json_exit(array('flag'=>'nolevel','jumpurl'=>$jumpurl,'msg'=>''.$chat_send_iffree_str.'才可以主动发信<br>您当前<font class=Cf00>【'.utitle($cook_grade).'】</font>'));
		}
		nolevel($uid,$cook_uid,'chat',$jumpurl);
		//发信需要解锁
		if(!$ifchatlock){
			if($chat_duifangfree_send[$Ugrade]!=1){//对方免费发信
				if($chat_hf_iffree[$cook_grade]==1){//免费回信
					$total = $db->COUNT(__TBL_UCOUNT__,"FIND_IN_SET($cook_uid,listed) AND kind='chat' AND uid=".$uid);
					if($total<=0){//我不在他里面，进行解锁
						//nolevel($uid,$cook_uid,'chat',$jumpurl);
						noucount_clickloveb($uid,$cook_uid,'chat');
					}
				}else{
					//nolevel($uid,$cook_uid,'chat',$jumpurl);
					noucount_clickloveb($uid,$cook_uid,'chat');
				}
			}
		}
		//发信解锁结束
		if (!empty($content)){
			$content = trimhtml($content);
			$content = dataIO($content,'in');
			if (gzflag($cook_uid,$uid) == -1){$db->query("INSERT INTO ".__TBL_MSG__." (uid,senduid,content,addtime,ifdel) VALUES ($uid,$cook_uid,'$content',".ADDTIME.",1)");exit;}
			//
			$sendwx = false;
			$SQL = " WHERE (uid=".$uid." AND senduid=".$cook_uid.") OR (senduid=".$uid." AND uid=".$cook_uid." AND ifdel=0) ";
			$rtt = $db->query("SELECT addtime FROM ".__TBL_MSG__.$SQL." ORDER BY id DESC LIMIT 1");
			if ($db->num_rows($rtt)){
				$roww = $db->fetch_array($rtt,'num');
				$endtime = $roww[0];
				$difftime = ADDTIME - $endtime;
				if ($difftime > 60 ){
					$sendwx = true;
				}
			}else{$sendwx = true;}
			if ($sendwx){
				$mbnickname = urlencode($cook_nickname.' UID:'.$cook_uid);
				$first  = urlencode("您好，在 ".date("Y-m-d H:i:s",ADDTIME)." 有人给你留言");
				$remark = urlencode("缘份就在一瞬间，赶快去看看~");
				//$mbcontent = (strstr($content,"[/img]"))?'[表情]':'聊天内容进入查看';//$content
				$mbcontent = '聊天内容进入查看';
				//if($cook_grade<2){
				//	$mbcontent='*************';
				//}
				@wx_mb_sent('mbbh=ZEAI_MSG_CHAT&openid='.$openid.'&content='.$mbcontent.'&nickname='.$mbnickname.'&first='.$first.'&remark='.$remark.'&url='.urlencode(mHref('my_chat')));
			}
			$db->query("INSERT INTO ".__TBL_MSG__." (uid,senduid,content,addtime) VALUES ($uid,$cook_uid,'$content',".ADDTIME.")");
			$db->query("UPDATE ".__TBL_USER__." SET tipnum=tipnum+1 WHERE id=".$uid);
		}
		json_exit(array('flag'=>1));
	break;
	case 'ajax_chat_audio':
	
		//发信总开关
		if(!$ifchatlock && $chat_send_iffree[$cook_grade]!=1){
			$chat_send_iffree_str='';
			foreach (@$urole as $uv){
				$grade = $uv->g;
				$title = $uv->t;
				if($chat_send_iffree[$grade]==1)$chat_send_iffree_str.='【'.$title.'】<br>';
			}
			if(empty($chat_send_iffree_str))$chat_send_iffree_str='VIP';
			json_exit(array('flag'=>'nolevel','jumpurl'=>$jumpurl,'msg'=>''.$chat_send_iffree_str.'才可以主动发信<br>您当前<font class=Cf00>【'.utitle($cook_grade).'】</font>'));
		}
		//发信需要解锁
		if(!$ifchatlock){
			if($chat_duifangfree_send[$Ugrade]!=1){//对方免费发信
				if($chat_hf_iffree[$cook_grade]==1){//免费回信
					$total = $db->COUNT(__TBL_UCOUNT__,"FIND_IN_SET($cook_uid,listed) AND kind='chat' AND uid=".$uid);
					if($total<=0){//我不在他里面，进行解锁
						nolevel($uid,$cook_uid,'chat',$jumpurl);
						noucount_clickloveb($uid,$cook_uid,'chat');
					}
				}else{
					nolevel($uid,$cook_uid,'chat',$jumpurl);
					noucount_clickloveb($uid,$cook_uid,'chat');
				}
			}
		}
		if (str_len($sid) > 20){
			require_once ZEAI.'sub/zeai_up_func.php';
			$dbname   = setVideoDBname('v',$cook_uid,'amr');
			$file     = get_wx_datastream($sid);
			$difftime = ceil($difftime/1000);
			if (up_send_stream($file,$dbname,'www','a9a','cn','Sup_Des','audio')){
				//$content = dataIO($content,'in');
				$_s      = substr($dbname,0,str_len($dbname)-4);
				$content = $sid.'|'.$_s.'|'.$difftime.'|'.ADDTIME;
				if (gzflag($cook_uid,$uid) == -1){$db->query("INSERT INTO ".__TBL_MSG__." (uid,senduid,t,content,addtime,ifdel) VALUES ($uid,$cook_uid,2,'$content',".ADDTIME.",1)");exit;}
				//
				$db->query("INSERT INTO ".__TBL_MSG__." (uid,senduid,t,content,addtime) VALUES ($uid,$cook_uid,2,'$content',".ADDTIME.")");
				$db->query("UPDATE ".__TBL_USER__." SET tipnum=tipnum+1 WHERE id=".$uid);
				//
				$SQL = " WHERE (uid=".$uid." AND senduid=".$cook_uid.") OR (senduid=".$uid." AND uid=".$cook_uid." AND ifdel=0) ";
				$rtt = $db->query("SELECT addtime FROM ".__TBL_MSG__.$SQL." ORDER BY id DESC LIMIT 1");
				if ($db->num_rows($rtt)){
					$roww = $db->fetch_array($rtt,'num');
					$endtime = $roww[0];
					$difftime = ADDTIME - $endtime;
					if ($difftime > 60 ){
						$content2 = '语音消息';
						$nickname = urlencode($cook_nickname);
						//$url = $_ZEAI['m_2domain']."/msg/show.php?uid=".$cook_uid;
						//$url = HOST."/msg";
						$first  = urlencode("您好，在 ".date("Y-m-d H:i:s",ADDTIME)." 有人给你留言");
						$remark = urlencode("点击进入查看");
						$content2 = urlencode($content2);
						@wx_mb_sent('mbbh=OPENTM202119578&openid='.$openid.'&content='.$content2.'&nickname='.$nickname.'&first='.$first.'&remark='.$remark.'&url='.$url);
					}
				}
				//
				//echo $content;ob_end_flush();exit;
				json_exit(array('flag'=>1,'sid'=>$sid,'path_s'=>$_s,'difftime'=>$difftime,'t'=>ADDTIME));
			}
		}
		exit;
	break;
	case 'ajax_app_audio':
		if ($difftime>0){
			require_once ZEAI.'sub/zeai_up_func.php';
			$dbname   = setVideoDBname('v',$cook_uid,'amr');
			$file=$_FILES['file'];			
			$difftime = ceil($difftime/1000);
			if (up_send($file,$dbname,'www','zeai','cn','SupDes','audio')){
				$_s      = substr($dbname,0,str_len($dbname)-4);
				$content = 'app|'.$_s.'|'.$difftime.'|'.ADDTIME;
				if (gzflag($cook_uid,$uid) == -1){$db->query("INSERT INTO ".__TBL_MSG__." (uid,senduid,t,content,addtime,ifdel) VALUES ($uid,$cook_uid,2,'$content',".ADDTIME.",1)");exit;}
				//
				$db->query("INSERT INTO ".__TBL_MSG__." (uid,senduid,t,content,addtime) VALUES ($uid,$cook_uid,2,'$content',".ADDTIME.")");
				$db->query("UPDATE ".__TBL_USER__." SET tipnum=tipnum+1 WHERE id=".$uid);
				//
				$SQL = " WHERE (uid=".$uid." AND senduid=".$cook_uid.") OR (senduid=".$uid." AND uid=".$cook_uid." AND ifdel=0) ";
				$rtt = $db->query("SELECT addtime FROM ".__TBL_MSG__.$SQL." ORDER BY id DESC LIMIT 1");
				if ($db->num_rows($rtt)){
					$roww = $db->fetch_array($rtt,'num');
					$endtime = $roww[0];
					$difftime = ADDTIME - $endtime;
					if ($difftime > 60 ){
						$content2 = '语音消息';
						$nickname = urlencode($cook_nickname);
						$first  = urlencode("您好，在 ".date("Y-m-d H:i:s",ADDTIME)." 有人给你留言");
						$remark = urlencode("点击进入查看");
						$content2 = urlencode($content2);
						@wx_mb_sent('mbbh=OPENTM202119578&openid='.$openid.'&content='.$content2.'&nickname='.$nickname.'&first='.$first.'&remark='.$remark.'&url='.$url);
					}
				}
				//
				echo $content;ob_end_flush();exit;
			}
		}
		exit;
	break;
	case 'ajax_getmess':
		$C = get_mess_list($uid);
		echo $C;exit;
	break;
	case 'ajax_chk_flag':
		$rtD=$db->query("SELECT id FROM ".__TBL_MSG__." WHERE new=1 AND uid=".$cook_uid." AND senduid=".$uid." LIMIT 1");
		if ($db->num_rows($rtD)){
			$flag = 1;
		}else{$flag = 0;}
		echo $flag;exit;
	break;
	case 'ajax_getmess_one':
		$C = get_mess_list_one($uid);
		echo $C;exit;
	break;
	case 'ajax_getMsgMore':
		echo ajax_getMsgMore($uid,$p);exit;
	break;
}
function get_mess_list_one($uid){ 
	global $db,$cook_uid,$photo_s_str,$cook_photo_s_str,$ifchatlock,$chat_duifangfree,$cook_grade;
	$C = "";
	$SQL = " WHERE (senduid=".$uid." AND uid=".$cook_uid.") AND new=1 AND ifdel=0";
	$rt=$db->query("SELECT t,content,addtime,senduid FROM ".__TBL_MSG__.$SQL." ORDER BY id DESC");
	$total = $db->num_rows($rt);
	if ($total > 0){
		while($tmprows = $db->fetch_array($rt,'num')){
			if(!$ifchatlock && $chat_duifangfree[$cook_grade]!=1){
				$tmprows[1] = '<div class=\'lock\' onClick=\"javascript:lockopen('.$tmprows[3].')\" >此条信息已隐藏<br>您与TA的聊天通道还没打开<a><i class=\'ico\'>&#xe620;</i>点击解锁</a></div>';
			}
			$arr[]=$tmprows;
		}
		$arr = array_reverse($arr);
		$db->query("UPDATE ".__TBL_MSG__." SET new=0 WHERE senduid=".$uid." AND uid=".$cook_uid." AND new=1 AND ifdel=0");
		$endnum = ($data_tipnum >= $total)?($data_tipnum - $total):0;
		$db->query("UPDATE ".__TBL_USER__." SET tipnum=$endnum WHERE id=".$cook_uid);
		$C=encode_json($arr);
	}
	return $C;
}
//初次载入
function get_mess_list($uid){ 
	global $db,$cook_uid,$cook_grade,$photo_s_str,$cook_photo_s_str,$data_tipnum,$ifchatlock,$chat_duifangfree,$Ugrade,$birthday,$heigh,$pay,$edu;
	$C = "";
	$SQL      = " (uid=".$uid." AND senduid=".$cook_uid.") OR (senduid=".$uid." AND uid=".$cook_uid.") ";
	$totalnum = $db->COUNT(__TBL_MSG__,$SQL);
	$ifmore   = ($totalnum > 10)?1:0;
	$rt=$db->query("SELECT senduid,t,content,addtime,ifdel,uid FROM ".__TBL_MSG__." WHERE ".$SQL." ORDER BY id DESC LIMIT 10");
	$total     = $db->num_rows($rt);
	if ($total == 0) {
		$C = '<dl><dt><a href="'.mHref('u',$uid).'">'.$photo_s_str.'</a></dt><dd>'.dzh_getcontent($birthday,$heigh,$pay,$edu).'</dd></dl>';
		$C .= '<div class="firsttips zeaicolor"><i class="ico">&#xe604;</i> 聊天涉及钱财和个人隐私问题<br>请保持警惕，避免上当受骗<br>切勿随意泄漏个人联系方式<br>若发现可疑行为，请及时举报</div>';
	} else {
		while($tmprows = $db->fetch_array($rt,'num')){$arr[]=$tmprows;}
		$arr = array_reverse($arr);
		foreach ($arr as $rows) {
			$senduid  = $rows[0];
			$t         = $rows[1];
			$content   = dataIO($rows[2],'out');
			$addtime   = $rows[3];
			$ifdel     = $rows[4];
			$uid____   = $rows[5];
			$ifhide=false;
			if ($senduid == $cook_uid){
				$ifmy = 1;$Uphoto = $cook_photo_s_str;
				$href='javascript:;';
			}else{
				$ifmy = 0;$Uphoto = $photo_s_str;
				if(!$ifchatlock && $chat_duifangfree[$cook_grade]!=1){//Ugrade
					$content = '<div class="lock" onClick="javascript:lockopen('.$senduid.')" title="点击解锁">此条信息已隐藏<br>您与TA的聊天通道还没打开<a><i class="ico">&#xe620;</i>点击解锁</a></div>';
					$ifhide=true;
				}
				$href=a('{"kind":"u","mp":"m","uid":"'.$senduid.'"}');
			}
			if ($ifdel == $cook_uid)continue;
			$difftime  = $addtime - $lasttime;
			if ($difftime > 60)$C .= "<span>".date("Y/m/d H:i",$addtime)."</span>";
			$ifmy = ($ifmy == 1)?" class='my'":"";
			switch ($t) {
				case 1:break;
				case 2:
					if(!$ifhide){
						$a        = explode('|',$content);
						$sid      = $a[0];
						$path_s   = $a[1] .'.mp3';
						$difftime = $a[2];
						$difftime = ($difftime>100)?3:$difftime;
						$content  = "<em voiceId=\"".$sid."\" src=\"".$path_s."\" t=\"".$addtime."\"><div class=\"voiceIcon\"></div><div class=\"voiceSec\">".$difftime."\"</div></em>";		
					}
				break;
			}
			$C .= "<dl".$ifmy."><dt".$photo_s_href."><a href='".$href."'>".$Uphoto."</a></dt><dd>".$content.$ifdel_str."</dd></dl>";
			$lasttime = $addtime;
		}
		$newnum = $db->COUNT(__TBL_MSG__,"new=1 AND senduid=".$uid." AND uid=".$cook_uid." AND ifdel=0");
		if ($newnum > 0){
			$db->query("UPDATE ".__TBL_MSG__." SET new=0 WHERE new=1 AND senduid=".$uid." AND uid=".$cook_uid." AND ifdel=0");
 			$endnum = ($data_tipnum >= $newnum)?($data_tipnum - $newnum):0;
			$db->query("UPDATE ".__TBL_USER__." SET tipnum=$endnum WHERE id=".$cook_uid);
		}
	}
	return $C."|GYL-SUPDES|".$ifmore;
}
function ajax_getMsgMore($uid,$p){ 
	global $db,$cook_uid,$cook_grade,$photo_s_str,$cook_photo_s_str,$ifchatlock,$chat_duifangfree;
	$pagesize = 10;$p = intval($p);$C = "";
	$SQL = " (uid=".$uid." AND senduid=".$cook_uid.") OR (senduid=".$uid." AND uid=".$cook_uid." AND ifdel=0) ";
	$total = $db->COUNT(__TBL_MSG__,$SQL);
	$totalpage = ceil($total/$pagesize);
	$LIMIT     = " LIMIT ".($p*$pagesize).",".$pagesize;
	$ifmore    = ($p < $totalpage)?1:0;
	if ($p <= $totalpage){
		$rt=$db->query("SELECT senduid,t,content,addtime FROM ".__TBL_MSG__." WHERE ".$SQL." ORDER BY id DESC".$LIMIT);
		$total = $db->num_rows($rt);
		if ($total > 0) {
			while($tmprows = $db->fetch_array($rt,'num')){$arr[]=$tmprows;}
			$arr = array_reverse($arr);
			foreach ($arr as $rows) {
				$senduid  = $rows[0];
				$t         = $rows[1];
				$content   = $rows[2];
				$addtime   = $rows[3];
				$difftime  = $addtime - $lasttime;
				if ($difftime > 60)$C .= "<span>".date("Y/m/d H:i",$addtime)."</span>";
				if ($senduid == $cook_uid){
					$ifmy = 1;$Uphoto = $cook_photo_s_str;
					$href='javascript:;';
				}else{
					$ifmy = 0;$Uphoto = $photo_s_str;
					
					if(!$ifchatlock && $chat_duifangfree[$cook_grade]!=1){//Ugrade
						$content = '<div class="lock" onClick="javascript:lockopen('.$senduid.')" title="点击解锁">此条信息已隐藏<br>您与TA的聊天通道还没打开<a><i class="ico">&#xe620;</i>点击解锁</a></div>';
					}
					
					$href=a('{"kind":"u","mp":"m","uid":"'.$senduid.'"}');
				}
				$ifmy = ($ifmy == 1)?" class='my'":"";
				switch ($t) {
					case 1:break;
					case 2:
						$a        = explode('|',$content);
						$sid      = $a[0];
						$path_s   = UP.$a[1] .'.mp3';
						$difftime = $a[2];
						$content  = "<em voiceId=\"".$sid."\" src=\"".$path_s."\" t=\"".$addtime."\"><div class=\"voiceIcon\"></div><div class=\"voiceSec\">".$difftime."\"</div></em>";
					break;
				}
				$C .= "<dl".$ifmy."><dt><a href='".$href."'>".$Uphoto."</a></dt><dd>".$content."</dd></dl>";
				$lasttime = $addtime;
			}
		}
	}
	return $C."|GYL-SUPDES|".$ifmore;
}
$urolenew = json_decode($_ZEAI['urole'],true);
$newarr=array();foreach($urolenew as $RV){if($RV['f']==1){$newarr[]=$RV;}else{continue;}}
$newarr=encode_json($newarr);
$urole =json_decode($newarr);
$chat_daylooknum = json_decode($_VIP['chat_daylooknum']);
$chat_loveb      = json_decode($_VIP['chat_loveb']);?>
<!doctype html><html><head><meta charset="utf-8">
<title>私信聊天</title>
<?php echo HEADMETA; ?>
<meta name="generator" content="www.Zeai.cn V9" />
<link href="<?php echo RES;?>m/css/m.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo HOST;?>/cache/zeaicolor.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo RES;?>m/css/chat.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<script src="<?php echo RES;?>www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/m.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<?php
if (is_weixin()){
	require_once ZEAI."api/weixin/jssdk.php";?>
	<script src="<?php echo RES;?>jweixin-1.2.0.js"></script>
	<script>
	wx.config({debug: false,
		appId: '<?php echo $signPackage["appId"];?>',
		timestamp: <?php echo $signPackage["timestamp"];?>,
		nonceStr: '<?php echo $signPackage["nonceStr"];?>',
		signature: '<?php echo $signPackage["signature"];?>',
		jsApiList: ['chooseImage','uploadImage','previewImage','hideMenuItems','onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','startRecord','stopRecord','onVoiceRecordEnd','uploadVoice','downloadVoice','playVoice','pauseVoice']
	});
	</script>
<?php }?>
<style>
#write i,#msg dl dt{background-image:url('<?php echo RES;?>msg_show.png');}
#msg .my dd em .voiceIcon,#msg dl dd em .voiceIcon{background-image:url("<?php echo RES;?>voicePlayRight.png");}
#msg .my dd{background-image:-webkit-linear-gradient(right,rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.5),rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.6))}
#msg .my dd:after{border-left-color:rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.5)}
#write table tr td:nth-child(3) a{background-image:-webkit-linear-gradient(left,rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.8),rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,1))}
<?php
echo '.TRnav_btn i{color:'.$_ZEAI['mob_mbcolor'].'}';
$browser=browser();
if($browser=='wx'){
	echo '#write .btnn{width:8rem}';
}else{
	echo '#write .btnn{width:4rem}';
}
?>
</style>
</head>
<body>
<?php
$mini_title=$nickname;
$mini_class='top_mini4';
//$mini_L = '<em onClick="zeai.back()"><i class="ico" >&#xeaca;</i></em>';
//$mini_R = '<a href="'.HOST.'"><i class="ico" >&#xe636;</i></a>';
require_once ZEAI.'m/top_mini.php';?>
<input type="hidden" id="ifopen" value="0">
<input type="hidden" id="p" value="1">
<input type="hidden" id="starttime" value="0">
<div class="chatmain" id="msgmask">
	<div class="chattop"></div>
    <div id="msg"></div>
    <div id="write">
        <table><tr>
        <td class="btnn"><?php if($browser=='wx'){?><i id="audiobtn" class="textbtn"></i><?php }?><i id="bqbtn"></i>
        </td>
        <td><div name="content" id="content" onclick="iput();" contentEditable="true" oninput="iput();" tabindex="0" hidefocus="true" onblur="onblurFN();"></div><div id="startRecord" contenteditable="false"></div></td>
        <td><a href="javascript:;" id="sendbtn" onclick="msg_send(<?php echo $uid; ?>);">发送</a></td>
        </tr></table>
    </div>
    <div id="bq">
        <div id="bqlist">
            <img src="<?php echo RES;?>bq/1.gif">
            <img src="<?php echo RES;?>bq/2.gif">
            <img src="<?php echo RES;?>bq/3.gif">
            <img src="<?php echo RES;?>bq/4.gif">
            <img src="<?php echo RES;?>bq/5.gif">
            <img src="<?php echo RES;?>bq/6.gif">
            <img src="<?php echo RES;?>bq/7.gif">
            <img src="<?php echo RES;?>bq/8.gif">
            <img src="<?php echo RES;?>bq/9.gif">
            <img src="<?php echo RES;?>bq/10.gif">
            <img src="<?php echo RES;?>bq/11.gif">
            <img src="<?php echo RES;?>bq/12.gif">
            <img src="<?php echo RES;?>bq/13.gif">
            <img src="<?php echo RES;?>bq/14.gif">
            <img src="<?php echo RES;?>bq/15.gif">
            <img src="<?php echo RES;?>bq/16.gif">
            <img src="<?php echo RES;?>bq/17.gif">
            <img src="<?php echo RES;?>bq/18.gif">
            <img src="<?php echo RES;?>bq/19.gif">
            <img src="<?php echo RES;?>bq/20.gif">
            <img src="<?php echo RES;?>bq/21.gif">
            <img src="<?php echo RES;?>bq/22.gif">
            <img src="<?php echo RES;?>bq/23.gif">
            <img src="<?php echo RES;?>bq/24.gif">
        </div>
    </div>
</div>
<div class="top"><div class='title'><a href="javascript:;" id="loadmore">查看历史消息</a></div></div>
<!---->
<div id="chat_daylooknumHelp" class="helpDiv">
    <ul>
    <?php
    foreach ($urole as $uv) {
        $grade = $uv->g;
        $title = $uv->t;
        $num   = $chat_daylooknum->$grade;
        $num_str = ($num>0)?' <font class="Cf00">'.$num.'</font> 人/天':' 无权聊天';
        $ifmy = ($cook_grade==$grade)?'　　<font class="Cf00">（我）</font>':'';
        $outA .= '<li>'.uicon($cook_sex.$grade).' '.$title.' <i class="ico">&#xe62d;</i>'.$num_str.$ifmy.'</li>';
    }echo $outA;
    ?>
    </ul>
    <button type="button" class="btn size3 zeaibg W100_ chatlock" onClick="zeai.openurl_('<?php echo HOST;?>/m/my_vip.php?jumpurl='+encodeURIComponent(jumpurl))"><i class="ico">&#xe6ab;</i> 开通会员</button>
</div>
<div id="chat_lovebHelp" class="helpDiv">
    <ul>
    <?php
    foreach ($urole as $uv) {
        $grade = $uv->g;
        $title = $uv->t;
		$numr  = $chat_daylooknum->$grade;
		$numr_str = ($numr>0)?' 免费解锁':' 无权聊天';
        $num   = $chat_loveb->$grade;
        $num_str = ($num>0 && $numr>0)?' <font class="Cf00">'.$num.'</font> '.$_ZEAI['loveB'].'/人':$numr_str;
        if($cook_grade==$grade){
            $ifmy = '　<font class="Cf00">（我）</font>';
            $myclkB=$num;
        }else{
            $ifmy = '';
        }
        $outI .= '<li>'.uicon($cook_sex.$grade).' '.$title.' <i class="ico">&#xe62d;</i>'.$num_str.$ifmy.'</li>';
    }echo $outI;
    ?>
    </ul>
    <a class="btn size3 HONG W50_ chatlock" onClick="clickloveb('chat',uid)"><i class="ico">&#xe633;</i> 单次解锁</a>
    <a class="btn size3 VIP W50_ chatlock" onClick="zeai.openurl('<?php echo HOST;?>/m/my_vip.php?jumpurl='+encodeURIComponent(jumpurl))"><i class="ico">&#xe6ab;</i> 开通会员</a>
</div>
<script src="<?php echo RES;?>jquery-1.7.2.min.js"></script>
<script src="<?php echo RES;?>m/js/chat.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script>
msgmask.addEventListener('touchmove',function(e) {e.preventDefault();});
msg.addEventListener('touchmove',function(e) {e.cancelBubble = true;});
var cook_uid = '<?php echo $cook_uid; ?>',
cook_photo_s = '<?php echo $cook_photo_s; ?>',
uid          = '<?php echo $uid; ?>',
photo_s_str  = '<?php echo $photo_s_str ; ?>',
cook_photo_s_str = '<?php echo $cook_photo_s_str ; ?>',
up2       = "<?php echo UP; ?>",
nickname = '<?php echo $nickname; ?>',
lovebstr = '<?php echo $_ZEAI['loveB']; ?>',
jumpurl  = '<?php echo $jumpurl;?>';
browser='<?php echo $browser;?>';
//var maincolor='<?php echo $_ZEAI['mob_mbcolor'];?>';
var H = $(window).height(),iflocal = true;
H = H/10 - 10.5;
$(function(){msgAudioLiPlay();});
if(browser=='wx'){wxRecord();}
/*else{
	audiobtn.onclick=function(){
		if(is_h5app()) {
			appRecord({url:HOST+'/m/chat.php?submitok=ajax_app_audio&uid='+uid},function(e){ajax_app_audio(e);});
		}else{
			zeai.msg('只有在微信打开才支持语音聊天');
		}
	}
}
*/
o('bqbtn').onclick = bqbtnFn;
o('msg').onclick = msgFn;
o('loadmore').onclick = function(){ajax_getMsgMore(uid);}
domm();
ajax_getmess(uid);
var chatdsq= setInterval("ajax_chk_flag(uid)",2000);
btm0 = setInterval("scrollTobtm()",200);
setTimeout("delbtm0()",1000);
cleandsj = chatdsq;
</script>
<?php require_once ZEAI.'m/TRnav.php';?>
</body></html>